package no18.javaio;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;

public class Redirecting {
	private final static String IN_FILE_NAME = "D:/work/project/complex/complex.thinkinjava/src/main/java/no18/javaio/test.txt";
	private final static String OUT_FILE_NAME = "D:/work/project/complex/complex.thinkinjava/src/main/java/no18/javaio/output.txt";

	public static void main(String[] args) throws IOException {
		//标准输出流连接控制台
		PrintStream console = System.out;
		
		BufferedInputStream in = new BufferedInputStream(new FileInputStream(IN_FILE_NAME));
		
		PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(OUT_FILE_NAME)));
		//将原本的标准输入,输出,异常流重定向到别的输入,输出流中
		System.setIn(in);
		System.setOut(out);
		System.setErr(out);
		//将InputStream构造成Reader   new InputStreamReader(System.in)
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s;
		while((s= br.readLine()) != null){
			System.out.println(s);
		}
		out.close();
		
	}
}
